<style>
    #home.container{
        min-height: 550px;
    }
</style>
<?php
//use Zend\Session\Container;
$mobile_detect = new \Frontend\Helper\MobileDetect();
$isMobile = $mobile_detect->isMobile();
$isTablet = $mobile_detect->isTablet();

$ios = $mobile_detect->is('iphone');
if( $mobile_detect->isAndroidOS() && $session->mobile ==false){
    $session->mobile = true;
    echo "<script>
       var conf =  confirm('Đã có app Minimall cho Android, Click oke để tải ngay!');
       if(conf == true){
           window.location.href='https://dl.dropboxusercontent.com/u/25125318/vellaapp/vellaandroidapp.apk';
       }
    </script>";
}

$search_val = $this->search_val;

$view = $this->view;
$translator = \Velacolib\Utility\Utility::translate();
isset($_GET['search_cat']) ? $search_cat = $_GET['search_cat']  : $search_cat = 0;
isset($_GET['search_loc']) ? $search_loc = $_GET['search_loc']  : $search_loc = 0;
isset($_GET['search_type']) ? $search_type = $_GET['search_type']  : $search_type = '';
isset($_GET['view']) ? $view = $_GET['view']  : $view = '';

?>
<div class="page-header" id="banner">
    <form action="/" method="get" name="search_form" id="">
        <div class="row" style="">
            <input type="hidden" name="view" value="<?=$view?>" />
            <div class="col-lg-4 col-sm-4 col-md-4" style="margin-top: 5px">
                <input type="text" id="search-input" name="search_val" class="form-control" placeholder="<?=$translator->translate('search_text')?>">
                <div class="loading_absolute">&nbsp</div>
            </div>

            <div class="col-lg-4 col-sm-4 col-md-4" style="margin-top: 5px">
                <select class="form-control" name="search_cat">
                    <option value="0"><?=$translator->translate('all')?></option>
                    <?php $cat = Velacolib\Utility\Utility::getCategoryArray(); ?>
                    <?php foreach($cat as $key_cat=>$val_cat){    ?>
                        <option <?php if($search_cat == $val_cat->id) {echo "selected='selected'"; } ?> value="<?php echo $val_cat->id ?>"><?php echo $val_cat->title ?></option>
                    <?php } ?>
                </select>
            </div>
            <div class="col-lg-4 col-sm-4 col-md-4" style="margin-top: 5px">
                <div class="input-group">
                    <select class="form-control" name="search_loc">
                        <?php $loc = Velacolib\Utility\Utility::getLocationArray(); ?>
                        <?php foreach ($loc as $k=>$c) { ?>
                            <option <?php if($search_loc == $k) {echo "selected='selected'"; } ?> value="<?php echo $k ?>"><?php echo $c ?></option>
                        <?php } ?>
                    </select>
                    <span class="input-group-btn">
                      <button class="btn btn_purple" id="send" value="Tìm" type="submit">Tìm</button>
                    </span>
                </div>

            </div>
        </div>
        <div class="row" style="margin: 10px">
            <label class="checkbox-inline">
                <input  type="radio" <?php if($search_type == 0) {echo "checked"; } ?>   name="search_type" id="inlineCheckbox2" value="0"> <?=$translator->translate('Sell')?>
            </label>
            <label class="checkbox-inline">
                <input  type="radio" <?php if($search_type == 1) {echo "checked"; } ?> name="search_type" id="inlineCheckbox1" value="1"> <?=$translator->translate('Buy')?>
            </label>

        </div>
    </form>
</div>
<div class="content-body" >
    <div class="row vela-col">
        <?php if($isMobile || $isTablet){

        }else{    ?>
            <div class="vela-sort-item " style="text-align: right">
                <a href="?view=grid"><i class="glyphicon glyphicon-th" title="Xem dạng lưới"></i></a>
                <a href="?view=list"><i class="glyphicon glyphicon-th-list" title="Xem dạng danh sách"></i></a>
            </div>
      <?php  }
         ?>

        <div class="" id="topic-wrapper">
            <?php if($result): ?>
            <?php foreach ($data as $item): ?>
                <div class="col-lg-4 col-sm-4 col-md-4 topic-item-grid">
                   <div class="item-grid">
                    <div class="topic_image">
                        <a href="/raovat/chitiet/<?php echo $item->slug ?>/<?=$item->id?>">
                            <img title="<?php echo $item->title ?>" alt="<?php echo $item->title ?>"  src="<?php echo $item->thumb ?>"  >
                        </a>
                    </div>
                    <div>
                        <div class="topic-title">
                            <a href="/raovat/chitiet/<?php echo $item->slug ?>/<?=$item->id?>">
                                [ <?php echo Velacolib\Utility\Utility::getProductType($item->topic_type); ?></php> ]
                                <?php echo $item->title; ?></a>
                        </div>
                        <div class="topic-info"><span class="price"><?=($item->price)?> <?=$translator->translate('currency')?></span>  <span class="time pull-right"><?php echo Velacolib\Utility\Utility::time_stamp($item->create_date); ?></span>
                        </div>

                        <div class="category">
                            <a class="text-info left" href="/?search_loc=<?php echo $item->topic_location; ?>">  <?php echo Velacolib\Utility\Utility::getLocationArray($item->topic_location); ?></a>
                            <?php if ($item->cat_id) { ?>
                                <a class="text-info right" href="/?search_cat=<?php echo $item->cat_id; ?>"> <?php $topic_cat = Velacolib\Utility\Utility::getTopicCat()->getCategories($item->cat_id);
                                    echo $topic_cat->title; ?></a>
                            <?php } ?>
                        </div>
                        <div class="clear_fix"></div>
                    </div>
                   </div>
                </div>
            <?php endforeach ?>
            <?php  endif ?>
            <?php if($result == false): ?>
            <div class="alert alert-danger alert-dismissable"">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            Không có kết quả nào phù hợp với từ khóa:  <b> <?= $search_val['search_val'] ?> </b> . Vui lòng tìm kiếm với từ khóa khác. Click <a href="/">here</a> !
        </div>
        <?php endif ?>

            <!-- topic item -->
            <!--paginator -->

            <!--end paginator -->
        </div>
        <!-- list item index -->
    <?php if($result): ?>
        <div class="row vela-col">
            <div class="col-lg-8 col-md-8 col-sm-8">
                <div class="row">
                    <?php
                    // add at the end of the file after the table
                    echo $this->paginationControl(
                    // the paginator object
                        $data,
                        // the scrolling style; see http://zf2.readthedocs.org/en/release-2.1.4/modules/zend.paginator.usage.html#rendering-pages-with-view-scripts
                        'sliding',
                        // the partial to use to render the control
                        array('partial/paginator.phtml', 'index'),
                        // the route to link to when a user clicks a control link
                        array(
                            'route' => 'home',
                            'child_route' => array(
                                'controller' => 'index',
                                'action' => 'index',
                            ),
                            'search_val' => $search_val
                        )
                    );
                    ?>
                </div>
                <div class="col-lg-4 col-md-4 col-sm-4">
                    <div class="select_item_per_page">
                        <form action="/" method="get">
                            <?php
                            //unset($search_val['view']);
                            foreach($search_val as $s=>$sk){  ?>
                                <input type="hidden" name="<?php echo $s ?>" value="<?php echo $sk ?>">
                            <?php }
                            ?>
                            <?=$translator->translate('Topics/pages')?>
                            <select name="ipg" id="ipg" onchange="this.form.submit()">
                                <option value="50">50</option>
                                <option <?php if ($ipg == 100) echo "selected='selected'"; ?> value="100">100</option>
                                <option <?php if ($ipg == 150) echo "selected='selected'"; ?> value="150">150</option>
                            </select>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <?php endif ?>

    </div>
</div>
<script src="<?php echo $this->basePatch ?>/templates/front/js/masonry.pkgd.min.js"></script>
<script src="<?php echo $this->basePatch ?>/templates/front/js/masonry.js"></script>
<script>

    $(window).load(function () {
          $('.container').css('background-color','transparent') ;
          var container = document.querySelector('#topic-wrapper');
          var msnry = new Masonry(container, {
              // options
              columnWidth: 0,
              itemSelector: '.topic-item-grid'
          });


      })  ;
</script>